package com.easyadmin.modules.stock.service.impl;




import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.easyadmin.common.web.domain.request.PageDomain;
import com.easyadmin.modules.stock.domain.SysDailyTopicThinkEntity;
import com.easyadmin.modules.stock.domain.SysFuturesEntity;
import com.easyadmin.modules.stock.mapper.SysDailyTopicThinkDao;
import com.easyadmin.modules.stock.service.SysDailyTopicThinkService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service("sysDailyTopicThinkService")
public class SysDailyTopicThinkServiceImpl extends ServiceImpl<SysDailyTopicThinkDao, SysDailyTopicThinkEntity>
        implements SysDailyTopicThinkService {


    @Autowired
    private SysDailyTopicThinkDao sysDailyTopicThinkDao;


    @Override
    public PageInfo<SysDailyTopicThinkEntity> queryPage(SysDailyTopicThinkEntity sysDailyTopicThinkEntity, PageDomain pageDomain) {
        PageHelper.startPage(pageDomain.getPage(), pageDomain.getLimit());
        List<SysDailyTopicThinkEntity> data =sysDailyTopicThinkDao.selectList(new QueryWrapper<SysDailyTopicThinkEntity>().lambda()
                .eq(StringUtils.isNotBlank(sysDailyTopicThinkEntity.getType()),
                        SysDailyTopicThinkEntity::getType,sysDailyTopicThinkEntity.getType())
                .like(StringUtils.isNotBlank(sysDailyTopicThinkEntity.getTitle()),
                        SysDailyTopicThinkEntity::getTitle,sysDailyTopicThinkEntity.getTitle()));
        return new PageInfo<>(data);
    }

    @Override
    public Boolean remove(String id) {
        sysDailyTopicThinkDao.deleteById(Integer.valueOf(id));
        return true;
    }

    @Override
    public boolean update(SysDailyTopicThinkEntity sysDailyTopicThinkEntity) {
        sysDailyTopicThinkEntity.setUpdateTime(new Date());
        Integer result = sysDailyTopicThinkDao.updateById(sysDailyTopicThinkEntity);
        return result > 0;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean batchRemove(String[] ids) {
        for(String  id:ids){
            sysDailyTopicThinkDao.deleteById(id);
        }
        return true;
    }
}
